home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / Installer SDK Cornucopia 1.0.2 / Script Examples / System Rules - Desk Accessory / daRules.r < prev    next >
Encoding:
Text File  |  1996-09-27  |  16.6 KB  |  489 lines  |  [TEXT/MPS ]

  1. //
  2. //    daRules.r
  3. //
  4. //        Includes : system version screening, as well as customized user interface 
  5. //        and installation contents, based on existing system version of selected 
  6. //        target volume.
  7. //
  8. //        This example will install a Desk Accessory with the method proper to
  9. //        the existing system folder on the selected target volume. Installation
  10. //        of a Desk Accessory was chosen for this example because this is one of
  11. //        the many cases where you may need to provide different installations
  12. //        based upon which version of the operating system the user has.
  13. //
  14. //        Your needs may differ from this example. Many developers produce
  15. //        applications that are dependent on System 7, and will not run under
  16. //        System 6. In those cases, simply add a package containing your software
  17. //        if the proper system version is found on the selected target volume.
  18. //
  19. //        If a proper system version cannot be found on the target volume
  20. //        you may add the rule clause ReportVolError to dim or disable the Install
  21. //        button in the dialog to prevent the user from installing software
  22. //        that is inappropriate for the selected volume.
  23. //
  24. //        In this example we have arbitrarily chosen System 6.0 as the minimum
  25. //        system required for installation. Your Desk Accessory may have different
  26. //        requirements.
  27. //
  28. //        You may wish to allow the user to install software that falls outside
  29. //        of the recommended installation. Use Custom Install for these cases.
  30. //
  31. //        This example checks for system version by checking the file version
  32. //        of the System file on the selected target volume. This is not necessarily
  33. //        the version of the currently running operating system. Users may have
  34. //        different versions of system folders on different hard disks. The system
  35. //        version that will be checked is that of the blessed system folder
  36. //        on the currently selected target volume.
  37. //
  38. //        The CheckFileVersion call will look for an active system folder on 
  39. //        the selected target volume when checking the version of the System
  40. //        file. The target spec used in the CheckFileVersion call uses the path
  41. //        "special-macs:" which will look for an existing blessed system folder.
  42. //        Once the blessed system folder has been found, target spec will 'point'
  43. //        to the System file within the blessed system folder. If no blessed system
  44. //        folder is found, path "special-macs:" will default to ":System Folder:".
  45. //        In the case where the user has removed the Finder file from folder named
  46. //        "System Folder" that still contains a copy of the System file, this check
  47. //        for an existing system version on the target volume may be erroneous.
  48. //
  49. //
  50. //        IMPORTANT: As of Installer version 4.0.3, the ReportVolError and
  51. //        ReportSysError rule clauses do not function correctly when used 
  52. //        within the Global framework. Both rule clauses should disable the 
  53. //        Install button, and ReportSysError should disable the Switch Disk 
  54. //        button. Currently, when either of these rule clauses is evoked from 
  55. //        within the Global framework neither the Install or Switch Disk buttons 
  56. //        are disabled. Both rule clauses do work correctly within the Easy and 
  57. //        Custom frameworks. As a result, it is recommended that Report Error 
  58. //        clauses be implemented within Easy and Custom frameworks exclusively.
  59. //
  60. //        Copyright 1993-1996, Apple Computer, Inc., All Rights Reserved
  61. //
  62.  
  63. #include "InstallerTypes.r"
  64.  
  65.  
  66. // constants for packages, comments, comment text
  67. #define     k70Package            200        // package for 7.0
  68. #define     k60Package            300        // package for 6.0
  69.  
  70. #define     kCurrentReleaseDate    8151994    // dummy date ( just today's date )
  71. #define     kCurrentVersion        403     // dummy version ( from installer vers )
  72.  
  73. // target spec of system file for comparing system versions
  74. // as well as the target spec for 6.0 installs
  75. #define     kSystemFileTarget         20000
  76.  
  77. #define     kKeyCaps70FileTarget     20001
  78.  
  79. // source spec of Key Caps file ( for both 7.0 and 6.0 installs )
  80. #define     kKeyCapsSourceSpec         20002
  81.  
  82. #define     kEasy70Rule                8070
  83. #define     kEasy60Rule                8060
  84.  
  85. #define     kCustom70Rule            9070
  86. #define     kCustom60Rule            9060
  87.  
  88. #define     kBadVersionRule            9999
  89.  
  90.  
  91. // • easy install setup
  92.  
  93. // easy install framework uses ID other than 765 or 766
  94. // recommended to always use ID 764
  95. resource 'infr' (764) {
  96.     format0 {{
  97.         // execute first true rule
  98.         pickFirst, { kEasy70Rule, kEasy60Rule,     // check system version 
  99.                      kBadVersionRule },         // if not supported give error
  100.                                                      
  101.     }}
  102. };
  103.  
  104. resource 'inrl' ( kEasy70Rule ) {
  105.     format0 {{
  106.         // check for 7.0 or greater
  107.         CheckFileVersion{     kSystemFileTarget,     // target file spec
  108.                             7,                     // major revision
  109.                             0,                     // minor revision
  110.                             release,             // release stage
  111.                             0 },                // incremental version
  112.         
  113.         // if 7.0 or greater add System 7 package
  114.         AddPackages{{ k70Package }},
  115.         AddUserDescription{ "Install KeyCaps Desk Accessory "
  116.                             "for use under System 7." },
  117.     }}
  118. };
  119.  
  120. resource 'inrl' ( kEasy60Rule ) {
  121.     format0 {{
  122.         // check for 6.0 or greater
  123.         CheckFileVersion{     kSystemFileTarget,     // target file spec
  124.                             6,                     // major revision
  125.                             0,                     // minor revision
  126.                             release,             // release stage
  127.                             0 },                // incremental version
  128.         
  129.         // if 6.0 or greater add System 6 package
  130.         AddPackages{{ k60Package }},
  131.         AddUserDescription{ "Install KeyCaps Desk Accessory "
  132.                             "for use under System 6." },
  133.     }}
  134. };
  135.  
  136.  
  137. // • custom install setup
  138.  
  139. // custom install framework always uses ID of 766
  140. resource 'infr' (766) {
  141.     format0 {{
  142.         // execute first true rule
  143.         pickFirst, { kCustom70Rule, kCustom60Rule,     // check system version, 
  144.                      kBadVersionRule },                // if not supported give error
  145.                                                     
  146.     }}
  147. };
  148.  
  149. // rule that checks system version of target volume
  150. resource 'inrl' ( kCustom70Rule ) {
  151.     format0 {{
  152.         // this returns false unless system version is greater than 7.0
  153.         CheckFileVersion{     kSystemFileTarget,         // target file spec
  154.                             7,                         // major revision
  155.                             0,                         // minor revision
  156.                             release,                 // release stage
  157.                             0 },                    // incremental version
  158.         
  159.         AddCustomItems{{ k70Package }},
  160.     }}
  161. };
  162.  
  163. // rule that checks system version of target volume
  164. resource 'inrl' ( kCustom60Rule ) {
  165.     format0 {{
  166.         // this returns false unless system version is greater than 6.0
  167.         CheckFileVersion{     kSystemFileTarget,         // target file spec 
  168.                             6,                         // major revision
  169.                             0,                         // minor revision
  170.                             release,                 // release stage
  171.                             0 },                    // incremental version
  172.         
  173.         AddCustomItems{{ k60Package }},
  174.     }}
  175. };
  176.  
  177. // • used in both easy and custom
  178.  
  179. // generate an error symbol, disable INSTALL button, display an error message
  180. resource 'inrl' ( kBadVersionRule ) {
  181.     format0 {{
  182.         ReportVolError{ "System 6.0 or greater required for installation !!" }
  183.     }}
  184. };
  185.  
  186. // • packages
  187.  
  188. // 7.0 or greater
  189. resource 'inpk' ( k70Package ) {
  190.     format0 {
  191.         showsOnCustom,            // if this was a subpackage, 
  192.                                 // it would be listed in Custom Install
  193.                                 
  194.         removable,                // include this package or subpackage 
  195.                                 // as a removeable item
  196.                                 
  197.         dontForceRestart,        // don't make  user reboot  after installation
  198.         k70Package,                // 'inpc' resource ID ( item defined below )
  199.         0,                        // Package size ( if 0, filled in by ScriptCheck )
  200.         
  201.         "KeyCaps DA in Apple Menu", // Custom Install selection text
  202.                                 
  203.                                 
  204.         {    // Package parts list ( all the stuff to be include in package )
  205.             // These parts can be 'inpk', 'infa', 'inra', 'inr#', 'inrm',
  206.             // 'inff', 'infm', 'inaa', 'inat', 'inat', or 'inbb'
  207.                                 
  208.         'infa', 1070;            // file atom
  209.                                 // 7.0 Key Caps Desk Acessory
  210.         },
  211.     }
  212. };
  213.  
  214. // 6.0 or greater
  215. resource 'inpk' ( k60Package ) {
  216.     format0 {
  217.         showsOnCustom,            // if this was a subpackage, 
  218.                                 // it would be listed in Custom Install
  219.                                 
  220.         removable,                // include this package or subpackage 
  221.                                 // as a removeable item
  222.                                 
  223.         dontForceRestart,        // don't make  user reboot  after installation
  224.         k70Package,                // 'inpc' resource ID ( item defined below )
  225.         0,                        // Package size ( if 0, filled in by ScriptCheck )
  226.         
  227.         "KeyCaps DA in System File", // Custom Install selection text
  228.                                 
  229.                                 
  230.         {    // Package parts list ( all the stuff to be include in package )
  231.             // These parts can be 'inpk', 'infa', 'inra', 'inr#', 'inrm',
  232.             // 'inff', 'infm', 'inaa', 'inat', 'inat', or 'inbb'
  233.                                 
  234.         'inra', 1060;            // resource atom
  235.                                 // 6.0 Key Caps Desk Acessory
  236.         },
  237.     }
  238. };
  239.  
  240.  
  241.  
  242. // • package comments
  243.  
  244. //     NOTE: The values that are assigned to the Custom Package Information 
  245. //    resource fields do not actually have any affect on the installation and 
  246. //    are ignored during installation. They can however assist the user in 
  247. //    choosing which packages they would like to include in their Custom 
  248. //    Installation or Custom Removal.
  249.  
  250. //     The following included file contains the icons for the two package comments.
  251. //     The file with the icon resources ( 'ICN#', 'icl4' and 'icl8' ) was created
  252. //     by doing a "Get Info" (from File menu in Finder) on the file to be
  253. //  installed. Then, the file icon in the "Get Info" dialog was selected,
  254. //  copied, and then pasted into a new ResEdit file  called "Icons.rsrc".  All
  255. //  icon resources were then deleted except for the 'ICN#', 'icl4' and 'icl8' icon
  256. //  resources.  These remaining resource items were assigned an ID of 9128, since
  257. //  their original resource ID's had a value that was illegal for use with 'inpc'
  258. //  resources ( they must be over 1024 ).
  259. //
  260.  
  261. include "Icons.rsrc";
  262.  
  263. resource 'inpc' ( k70Package ) {
  264.     format1 {
  265.         kCurrentReleaseDate,    // Date
  266.         kCurrentVersion,        // Version
  267.  
  268.         20 * 1024,                // RAM requirement for this package.
  269.                                 // This number is in bytes. To generate value of
  270.                                 // 1 meg in the dialog use ( 1000 * 1024 )
  271.                         
  272.         9128,                    // Icon rsrc ID ( 'ICON', 'ICN#', 'icl4', 'icl8' )
  273.                                 // - ID must be greater than 1024
  274.                                 // - resource item in rezzed script file
  275.  
  276.         k70Package,                // 'TEXT' resource ID of item  
  277.                                 // containing package description
  278.     }
  279. };
  280.  
  281. resource 'inpc' ( k60Package ) {
  282.     format1 {
  283.         kCurrentReleaseDate,    // Date
  284.         kCurrentVersion,        // Version
  285.  
  286.         20 * 1024,                // RAM requirement for this package.
  287.                                 // This number is in bytes. To generate value of
  288.                                 // 1 meg in the dialog use ( 1000 * 1024 )
  289.                         
  290.         9128,                    // Icon rsrc ID ( 'ICON', 'ICN#', 'icl4', 'icl8' )
  291.                                 // - ID must be greater than 1024
  292.                                 // - resource item in rezzed script file
  293.  
  294.         k60Package,                // 'TEXT' resource ID of item  
  295.                                 // containing package description
  296.     }
  297. };
  298.  
  299.  
  300. // The following resource items can easily be created manually by creating 'TEXT' 
  301. //  resource items in a file and including that file in this script.
  302. // USE: include "fileWithTextItem.rsrc";    
  303. // NOTE : resource includes use "include" instead of "#include" 
  304. //         and are terminated with a semicolon.
  305.  
  306. data 'TEXT' ( k70Package ) {
  307.     "This is some sample text that would describe what the 7.0 compatible "
  308.     "package contains."
  309. };
  310.  
  311. data 'TEXT' ( k60Package ) {
  312.     "This is some sample text that would describe what the 6.0 compatible "
  313.     "package contains."
  314. };
  315.  
  316.  
  317. // • file atoms
  318.  
  319. // file atom for the actual DA file to be installed for System 7
  320. resource 'infa' (1070) {
  321.     format1 {
  322.         deleteWhenRemoving,                //  Delete on deinstall
  323.         deleteWhenInstalling,            //  Remove preexisting
  324.         copy,                            //  Copy on Install
  325.  
  326.         dontIgnoreLockedFile,            //    Respect file locking
  327.         dontSetFileLocked,                //  Don't lock file after installation
  328.         useSrcCrDateToCompare,            //    Use date instead of version
  329.         srcNeedNotExist,                //    Install if new file
  330.         rsrcForkInRsrcFork,                //    Rrsc info stored in rsrc fork
  331.         leaveAloneIfNewer,                //    Don't update a newer file
  332.         updateExisting,                    //    Update if file already exists
  333.         copyIfNewOrUpdate,                //    Create new or update existing
  334.         rsrcFork,                        //    Copy rsrc info
  335.         dataFork,                        //    Copy data info
  336.         0,                                //    Size ( filled in by ScriptCheck )
  337.         
  338.         0x0,                            //    Finder attribute flags
  339.                                         //    ( filled in by ScriptCheck )
  340.                                         
  341.         kKeyCaps70FileTarget,    //  target spec for DA file
  342.         {    
  343.             kKeyCapsSourceSpec, //     Source spec for DA file
  344.             0,                     //     Data fork size ( filled in by ScriptCheck )
  345.             0                    //     Rsrc fork size ( filled in by ScriptCheck )
  346.         },
  347.         
  348.         0,                            //  The source version number in BCD format
  349.                                     //  ( if this value is zero, tgt file will
  350.                                     //    always be assumed to be older )
  351.                                     
  352.         0,                            //     Version compare procedure ( 0 : none )
  353.         
  354.         0,                            //  Atom extender resource ID ( 0 : none )
  355.         
  356.         ""                            //     Atom description 
  357.                                     //  ( if none installer will use filename )
  358.     }
  359. };
  360.  
  361. // • resource atoms
  362.  
  363. // resource atom for the DA rsrc item to be installed for System 6
  364. resource 'inra' (1060) {
  365.     format1 {
  366.         deleteWhenRemoving,                //  Delete on deinstall
  367.         dontDeleteWhenInstalling,        //  Do not remove preexisting
  368.         copy,                            //  Copy on Install
  369.         
  370.         leaveAloneIfNewer,                //  Do not update a newer file
  371.         tgtRequired,                    //  Target file must already exist
  372.         updateExisting,                    //  Update an existing file
  373.         copyIfNewOrUpdate,                //  Copy whether target exists or not
  374.         ignoreProtection,                //  Don't respect file locking
  375.         srcNeedExist,                    //  Source file must exist
  376.         byName,                            //  Use name instead of rsrc ID
  377.         nameMustMatch,                    //  Ignored when using 'byID'
  378.         
  379.         0,                    // TARGET - total resource size after installation
  380.                             // ( filled by ScriptCheck if 0 )
  381.                             
  382.         kSystemFileTarget,    // TARGET - file spec ( 'intf' )
  383.         'DRVR',                // TARGET - resource type 
  384.         0,                    // TARGET - resource ID ( ignored when using 'byName' )
  385.         
  386.         0x0,                // TARGET - resource attribute flags 
  387.                             // ( filled in by ScriptCheck if 0x0 )
  388.  
  389.         "\0x00Key Caps",    // TARGET - resource name 
  390.                             // this field must be when installing by ID
  391.         {    
  392.             kKeyCapsSourceSpec,    // SOURCE - file spec ( 'infs' )
  393.             'DRVR',                // SOURCE - resource type
  394.             14,                    // SOURCE - resource ID ( ignored when using 'byName' )
  395.             0,                    // SOURCE - resource size ( filled by ScriptCheck if 0 )
  396.             "\0x00Key Caps",    // SOURCE - resource name
  397.         },    
  398.         
  399.         0x0,                // SOURCE - version number for comparisons
  400.                             // 0x0 specifies not to perform version comparison
  401.                             
  402.         0,                    // 'invc' code resource - version comparison routine 
  403.                             // ( none used here )
  404.         
  405.         0,                    // 'inex' resource definition for atom extender
  406.                             // ( none used here )
  407.                             
  408.         "Key Caps DA",        // resource atom description                    
  409.     }
  410. };
  411.  
  412.  
  413. // • file specs
  414.  
  415. // target file spec to Apple Menu for Key Caps install to System 7
  416. resource 'intf' (kKeyCaps70FileTarget) {
  417.     format1 {
  418.         noSearchForFile,                 // use default search path
  419.         
  420.         TypeCrMustMatch,                 // If this is set to TypeCrMustMatch
  421.                                         // then a file with a different type
  422.                                         // and creator than those specified
  423.                                         // below will not be replaced.
  424.                                         // If this is set to TypeCrNeedNotMatch
  425.                                         // then type and creator of an existing
  426.                                         // target file are ignored.
  427.         
  428.         // The Type and Creator fields will be used to set the
  429.         // file's Type and Creator when a new file is created. 
  430.         'dfil',                         // TYPE for new file
  431.         'keyc',                         // CREATOR for new file
  432.         
  433.         0,                                 // finder attribute flags
  434.                                         // filled by ScriptCheck is value is 0
  435.         
  436.         1,                                  // creation date for new file
  437.         1,                                  // modification date for new file
  438.                                         // NOTE: DATE values are filled
  439.                                         // by ScriptCheck if the value is 1
  440.                                             
  441.         0,                                 // search proc ID ( 'insp' ), none used
  442.         
  443.         "special-amnu:Key Caps"         // path to target file
  444.         }
  445.     };
  446.  
  447. // source file spec for Key Caps for System 7 and for System 6
  448. resource 'infs' ( kKeyCapsSourceSpec ) {
  449.     'dfil',                        // TYPE for file search
  450.     'keyc',                        // CREATOR for file search
  451.  
  452.     0x1,                        // creation DATE for source file
  453.                                 // ( value of 1, filled in by ScriptCheck
  454.                                 
  455.     noSearchForFile,            // IGNORED in Installer 4.0.x
  456.     TypeCrMustMatch,            // TYPE, CREATOR must match file on install disk
  457.     "Disk 1:Key Caps"            // PATH to source file        
  458. };
  459.  
  460.  
  461.  
  462. // target file spec for checking System version on target
  463. // and for installing DA resource item to System file for System 6
  464. resource 'intf' (kSystemFileTarget) {
  465.     format1 {
  466.         noSearchForFile,                 // use default search path
  467.         
  468.         TypeCrNeedNotMatch,        // • because system type is different
  469.                                 // • under System 6 and 7 need to set
  470.                                 // • this flag to ignore type and creator
  471.                                 // • so that this file spec can be used
  472.                                 // • for both systems !!
  473.         
  474.         // These two fields will be ignored because TypeCrNeedNotMatch
  475.         // and this target spec is only used for referencing the System
  476.         // file. Nothing is actually installed using this target spec.
  477.         // But it woulda looked silly to give these bogus values...
  478.         'zsys',                         // TYPE for file
  479.         'MACS',                         // CREATOR for file
  480.         
  481.         0,                                 // finder attribute flags        
  482.         1,                                  // creation date for new file
  483.         1,                                  // modification date for new file
  484.         0,                                 // search proc ID ( 'insp' ), none used
  485.         
  486.         "special-macs:System"    // path to target file
  487.         }
  488.     };
  489.